/* Copyright (c) 2023, Arm Limited and Contributors. All rights reserved.
 * SPDX-License-Identifier: Apache-2.0
 */

#include "gtest/gtest.h"

#include "IotSocketToMbed.h"

TEST(TestIotSocketToMbed, TestIotSocketErrorToMbed)
{
    EXPECT_EQ(iotSocketErrorToMbed(0), NSAPI_ERROR_OK);
    EXPECT_EQ(iotSocketErrorToMbed(IOT_SOCKET_ERROR), NSAPI_ERROR_UNKNOWN);
    EXPECT_EQ(iotSocketErrorToMbed(IOT_SOCKET_ENOTSUP), NSAPI_ERROR_UNSUPPORTED);
    EXPECT_EQ(iotSocketErrorToMbed(IOT_SOCKET_ENOMEM), NSAPI_ERROR_NO_MEMORY);
    EXPECT_EQ(iotSocketErrorToMbed(IOT_SOCKET_EINPROGRESS), NSAPI_ERROR_IN_PROGRESS);
    EXPECT_EQ(iotSocketErrorToMbed(IOT_SOCKET_EAGAIN), NSAPI_ERROR_WOULD_BLOCK);
    EXPECT_EQ(iotSocketErrorToMbed(IOT_SOCKET_ETIMEDOUT), NSAPI_ERROR_CONNECTION_TIMEOUT);
    EXPECT_EQ(iotSocketErrorToMbed(IOT_SOCKET_EISCONN), NSAPI_ERROR_IS_CONNECTED);
    EXPECT_EQ(iotSocketErrorToMbed(IOT_SOCKET_EINVAL), NSAPI_ERROR_NO_SOCKET);
    EXPECT_EQ(iotSocketErrorToMbed(IOT_SOCKET_ESOCK), NSAPI_ERROR_NO_SOCKET);
    EXPECT_EQ(iotSocketErrorToMbed(IOT_SOCKET_ENOTCONN), NSAPI_ERROR_NO_CONNECTION);
    EXPECT_EQ(iotSocketErrorToMbed(IOT_SOCKET_ECONNRESET), NSAPI_ERROR_AUTH_FAILURE);
    EXPECT_EQ(iotSocketErrorToMbed(IOT_SOCKET_ECONNREFUSED), NSAPI_ERROR_AUTH_FAILURE);
    EXPECT_EQ(iotSocketErrorToMbed(IOT_SOCKET_ECONNABORTED), NSAPI_ERROR_CONNECTION_LOST);
    EXPECT_EQ(iotSocketErrorToMbed(IOT_SOCKET_EALREADY), NSAPI_ERROR_ALREADY);
    EXPECT_EQ(iotSocketErrorToMbed(IOT_SOCKET_EADDRINUSE), NSAPI_ERROR_ADDRESS_IN_USE);
    EXPECT_EQ(iotSocketErrorToMbed(IOT_SOCKET_EHOSTNOTFOUND), NSAPI_ERROR_HOST_NOT_FOUND);
    EXPECT_EQ(iotSocketErrorToMbed(-999), NSAPI_ERROR_UNKNOWN);
}
